<%@page import="com.alibaba.druid.sql.ast.expr.SQLCaseExpr.Item"%>
<%@page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%><!DOCTYPE HTML>
<%-- <%@include file="edit.jsp"%> --%>
<html>
	<head>
	<!-- 配置文件 -->
    <script type="text/javascript" src="${ctx}/static/admin/ueditor/ueditor.config.js"></script>
    <!-- 编辑器源码文件 -->
    <script type="text/javascript" src="${ctx}/static/admin/ueditor/ueditor.all.js"></script>
	</head>
<body>
	<div class="easyui-layout" data-options="fit:true">
		<div data-options="region:'center',border:false">
			<form id="dataform" action="updateTopic" method="post">
				<input type = "hidden" name="entity.id" value="${item.id}">
				<input type = "hidden" name="entity.userId" value="${item.userId}">
				<input type = "hidden" name="entity.groupId" value="${item.groupId}">
				<input type = "hidden" name="entity.articleContent" id="hidden_articleContent">
				<input type = "hidden" name = "entity.editorType" id = "add_editorType" value="${item.editorType}" /> 
				<input type = "hidden" name = "oldSoundId" value="${file.soundId}" id = "oldSoundId" /> 
				<input type = "hidden" id = "add_td_sound" /> 
				<input type = "hidden" id = "articleContent" name = "entity.articleContent" /> 
				<div id="article_main" class="easyui-panel" data-options="border:false">
				<table cellpadding="5" style="width:100%;height:100%;">
					<tr>
						<td>文章标题:</td>
						<td>
							<input class="easyui-textbox" name="entity.articleTitle" value="${item.articleTitle }" data-options="required:true"/>
						</td>
						<td>作者:</td>
						<td>
							<input class="easyui-textbox" name="entity.userName" value="${user.username}" data-options="required:true"/>
						</td>
					</tr>
					<tr>
						<td colspan="4">
							<script id="container" name="content" type="text/plain">
       						 文章内容
    						</script>
						</td>
					</tr>
					<tr>
						<td>文章类型:</td>
						<td>
							<select class="easyui-combobox" name="entity.articleType" id="comb_articleType" data-options="required:true,panelHeight:'auto' ">
								<option value="1">文章</option>
								<option value="3">音频 </option>
								<option value="5">视频</option>
								<option value="7">话题pk</option>
							</select>
						</td>
						<!-- <td>标签:</td>
						<td>
							<input class="easyui-combotreegrid" name="tagIds" id="comb_tagIds" value="" data-options="required:true,panelHeight:'auto' "/>
						</td> -->
					</tr>
					
					<tr class="form-tr">
						<td class="form-th">音频文件</td>
						<td class="form-td" id ="td_showSound">
							<audio controls="controls">
							<source src = "${ctx}${file.soundUrl}" type="audio/mpeg">
							</audio>
						</td>
						<td id="td_sound" class="form-td" colspan="2">
							<div>
	                            <input class="easyui-validatebox" type="hidden" id="sound_id" name="soundId" />
	                            <input id="file_upload_sound" name="file_upload_sound" type="file" multiple="multiple">
	                        </div>
						</td>
					</tr>
					<tr>
						
					</tr>
					<tr>
						<td>浏览量</td>
						<td>
							<input type="number" value="${item.countView}">
						</td>
						<td>点赞量</td>
						<td>
							<input type="number" value="${item.countPraise}">
						</td>
					</tr>
					<tr>
						<td>分享量</td>
						<td>
							<input type="number" value="${item.countShare}">
						</td>
						<td>收藏量</td>
						<td>
							<input type="number" value="${item.countCollect}">
						</td>
					</tr>

					<tr>
						<td>
							是否对所有人可见:
						</td>
						<td>
							<div id="markPublish" name="entity.markPublish" value="${item.markPublish}"></div>
						</td>
						<td>
							可用标记:
						</td>
						<td>
							<div id="enabled" name="entity.enabled" value="${item.enabled}" />
						</td>
					</tr>
				</table>
				</div> 
			</form>
		</div>
		<div data-options="region:'south',split:true" style="height:45px;text-align:right;padding:5px;">
			<a id="save_artile" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-ok'">保存</a>
			<a class="easyui-linkbutton" iconCls="icon-cancel" onclick="closeWin();">取&nbsp;消</a>
		</div>
		
	</div>
	
	
<script type="text/javascript">
var file = '${file.imgUrl}';
console.log(file);
//合并多个空白为一个空白  
String.prototype.ResetBlank = function() {        //对字符串扩展
    var regEx = /\s+/g;  
    return this.replace(regEx, ' ');  
}; 

var item = {  
		toolbars: [
		    [
		    	'undo', //撤销
		        'redo', //重做
		        'bold', //加粗
		        'indent', //首行缩进
		        'italic', //斜体
		        'underline', //下划线
		        'strikethrough', //删除线
		        'subscript', //下标
		        'fontborder', //字符边框
		        'superscript', //上标
		        'formatmatch', //格式刷
		        'source', //源代码
		        'selectall', //全选
		        'preview', //预览
		        'horizontal', //分隔线
		        'removeformat', //清除格式
		        'time', //时间
		        'date', //日期
		        'fontfamily', //字体
		        'fontsize', //字号
		        'paragraph', //段落格式
		    	'simpleupload', //单图上传
		    ]
		],  
          //autoHeightEnabled: true, //是否自动长高，默认true  
          //autoFloatEnabled: false, //是否保持toolbar的位置不动，默认true  
          wordCount: true, //是否开启字数统计 默认true  
          maximumWords: 100000, //允许的最大字符数 默认值：10000  
          wordOverFlowMsg: "<span style='color:red'>超出范围了！！！！！！！！</span>", //超出字数限制提示  
          elementPathEnabled: false, //是否启用元素路径  
          padding: 0,  
          saveInterval: 5000000, // 将其设置大点，模拟去掉自动保存功能  
          allowDivTransToP: false ,
          initialFrameWidth: 700,//初始化编辑器宽度，默认1000
          initialFrameHeight: 500, //初始化编辑器高度，默认320
      };  
     //传参生成实例  
     var ue = UE.getEditor('container',item); 
     
     UE.Editor.prototype._bkGetActionUrl = UE.Editor.prototype.getActionUrl;  
     UE.Editor.prototype.getActionUrl = function(action) { 
    	 console.log("action:"+action);
         if (action == 'uploadimage' || action == 'uploadscrawl' || action == 'uploadvideo') {  
             return '/uEditor/upload';  
         } else {  
             return this._bkGetActionUrl.call(this, action);  
         }  
     }  	
     var articleContent='${item.articleContent}';
     ue.ready(function() {
    	 ue.setContent(articleContent);
     });


	$(function(){
      //添加音频
        $('#file_upload_sound').uploadify({
        	'fileObjName' : 'file',
            'swf': '${ctx}/static/admin/uploadify/uploadify.swf',  //FLash文件路径
            'buttonText': '修改',                                 //按钮文本
            'uploader': '/file/upload',                       //处理文件上传Action
            'queueID': 'fileSound',                        //队列的ID
            'queueSizeLimit': 1,                          //队列最多可上传文件数量，默认为999
            'auto': true,                                 //选择文件后是否自动上传，默认为true
            'multi': true,                                 //是否为多选，默认为true
            'removeCompleted': true,                       //是否完成后移除序列，默认为true
            'fileSizeLimit': '30MB',                       //单个文件大小，0为无限制，可接受KB,MB,GB等单位的字符串值
            'fileTypeDesc': 'Image Files',                 //文件描述
            'fileTypeExts': '*.mp3',  //上传的文件后缀过滤器
            'onQueueComplete': function (event, data) {                 //所有队列完成后事件
                $.messager.alert("提示", "上传完毕！");                                     //提示完成           
            },
            'onUploadStart' : function(file) {
                $("#file_upload").uploadify("settings", 'formData', { 'folder': '文章音频'}); //动态传参数
            },
            'onUploadError': function (event, queueId, fileObj, errorObj) {
                //alert(errorObj.type + "：" + errorObj.info);
            },
            'onUploadSuccess':function(file,data,response){
            	var object = JSON.parse(data); 
            	$("#sound_id").val(object.data.id);  //完成后更新已上传的文件列表
            	var path ='${ctx}'+object.data.path+'/'+object.data.fileName;
            	console.log(path);
            	showSound(path);
            },
            'onDialogOpen':function(){
            	$('#file_upload_sound').uploadify('cancel', '*');
            } 
        });
        function showSound(path){
        	var html = '<audio controls="controls"><source id ="showSound" src = "'+path+'" type="audio/mpeg"></audio>';
			$("#td_showSound").html(html); 
		}
		
		$('#markPublish').radiobox({name:'entity.markPublish',value:'${item.markPublish}',data:[[true,'是'],[false,'否']]});
		$('#enabled').radiobox({name:'entity.enabled',value:'${item.enabled}',data:[[true,'是'],[false,'否']]});
		
		var articleType = '${item.articleType}';
		//类型
		$('#comb_articleType').combobox('select',articleType);
		//标签
		$('#comb_tagIds').combotreegrid({
       		width:'100%',
        	url:'/tag/info/treeModel',
        	method:'post',
        	multiple:true,//多选标记
        	idField:'id',
        	treeField:'tagName',
        	fitColumns:true,
        	panelHeight:100,
        	columns:[[
            	{field:'tagName',title:'名称'},
        		{field:'tagType',title:'类型',align:'center',formatter:function(v,r,i){
        			var type = "标签";
        			if(r.tagType =="1"){
        				type = "栏目";
        			}
        			return type;
        		}},
        		{field:'tagNote',title:'备注 '},
        		{field:'createdDt',title:'创建时间'},
        	]]
    	});
		$("#save_artile").on("click",function(){
			//获取富文本的内容
			var content = ue.getContent();
			$("#articleContent").val(content.ResetBlank());
			toSave();
		});
		 
		function toSave(){
			$.messager.progress({title:'系统提示',text:'数据处理中，请耐心等待...'});
			$.submit('#dataform',function(r) {
				$.messager.progress('close');
				if(r.code<0) return $alert(r.msg);
				top.$prompt('保存成功');
				top.$window.close(window,1,null);
			});
		}
	});
</script>
</body>
</html>